﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;
using MessageCallAspect.Inspector.Attributes;

namespace MessageCallAspect.Inspector.Aspect.Cache
{
    public class CacheAspectAttribute : MessageSinkAttribute
    {
        public double TimeoutMinute { get; set; }
        public CacheAspectAttribute()
        {
            Order = int.MaxValue;
        }
        public override IMessageSink CreateMessageSink(IModuleContext context, object target, IMessageSink nextSink)
        {
            CacheMessageSink cacheMessageSink = new CacheMessageSink(target, nextSink, context.GetService<ICacheProvider>());
            if (TimeoutMinute != 0)
            {
                cacheMessageSink.Timeout = TimeSpan.FromMinutes(TimeoutMinute);
            }
            return cacheMessageSink;

        }
    }
}
